import { Button } from "antd";
import React, { useReducer } from "react";

const INCREMENT = "increment_add";
interface State {
  age: number;
}

interface Action {
  type: string;
  payload: number;
}

function reducer(state: State, action: Action): State {
  if (action.type === INCREMENT) {
    return { age: state.age + action.payload };
  }
  throw Error("error");
}
const initState: State = { age: 28 };
const TestUseReducer: React.FC = () => {
  const [state, dispatch] = useReducer(reducer, initState);

  const handleAdd = () => {
    dispatch({ type: INCREMENT, payload: 2 });
  };

  return (
    <>
      <Button onClick={handleAdd}>增加</Button>
      <p>测试{state.age}</p>
    </>
  );
};
export default TestUseReducer;
